<template>
  <el-dialog
    title="通过"
    :visible.sync="isShowAdopt"
    width="30%"
    :destroy-on-close="true"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    center
  >
    <div class="title">
      <div class="img">
        <img src="../../../../assets/static/imgs/pass.png" />
        <p>确定通过该申报立项的审批吗？</p>
      </div>
      <div v-if="processObj.processName == '线下专家评审'">
        <el-upload
          style="margin-top: 20px"
          class="upload-demo"
          :action="uploadUrl"
          :on-success="handleSuccess"
          :headers="headers"
          :show-file-list="false"
        >
          <el-button size="small" type="primary">添加附件</el-button>
        </el-upload>

        <div
          class="upload-demo"
          v-for="(i, index) in params.filelist"
          :key="index"
        >
          <span @click="openDoc(i)">{{ i.fileName }}</span>
          <i @click="onRemove(index)" class="el-icon-circle-close"></i>
        </div>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="adoptApply(0)">取 消</el-button>
      <el-button
        type="success"
        style="background: #45b177"
        @click="adoptApply(1)"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import { uploadUrl } from "@/const";
import { getToken } from "@/utils/auth";
import { serverUrl } from "@/look";
import { Base64 } from "js-base64";

export default {
  props: {
    isShowAdopt: {
      type: Boolean,
      default: false,
    },
    processObj: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      uploadUrl,
      headers: {
        Authorization: getToken(),
        platform: 'WEB'
      },

      params: {
        approveResult: 0, //0 是通过
        filelist: [],
        specialistAppendixUrl: [], //附件地址
      },
    };
  },
  methods: {
    adoptApply(i) {
      console.log(this.params);
      this.$emit("adoptApplyFn", i, this.params);
      setTimeout(() => {
        this.params.filelist = [];
        this.params.specialistAppendixUrl = [];
      }, 1000);
    },
    // 文件上传成功
    handleSuccess(res) {
      console.log(res);
      let data = res.data;
      data.name = res.data.fileName;
      this.params.filelist.push(data);
      this.params.specialistAppendixUrl.push({
        fileName: data.fileName,
        url: data.url,
      });
    },
    // 附件预览
    openDoc(e) {
      window.open(
        serverUrl +
          "onlinePreview?url=" +
          encodeURIComponent(Base64.encodeURI(e.url))
      );
    },
    // 移除
    onRemove(index) {
      this.params.filelist.splice(index, 1);
      this.params.specialistAppendixUrl.splice(index, 1);
    },
  },
};
</script>

<style lang="scss" scoped>
.el-dialog__header {
  text-align: left;
}
.title {
  text-align: left;
  font-size: 1rem;
  color: #333333;
  .img {
    display: flex;
    align-items: center;
  }
  .upload-demo {
    margin: 0 auto;
    text-align: left;
  }
  p {
    margin-left: 1.25rem;
  }
}
</style>
